import { Controller, Post, UploadedFile, UploadedFiles, UseInterceptors, Body } from '@nestjs/common';
import { FileInterceptor, FilesInterceptor } from '@nestjs/platform-express';
import { UploadService } from './upload.service';
import { UploadFileDto } from './dto/upload-file.dto';
import { UploadFileResponseDto } from './dto/upload-response.dto';
import type { Express } from 'express';

@Controller('upload')
export class UploadController {
  constructor(private readonly uploadService: UploadService) {}

  @Post('file')
  @UseInterceptors(FileInterceptor('file'))
  async uploadFile(@UploadedFile() file: Express.Multer.File, @Body() uploadFileDto?: UploadFileDto) {
    const uploadFileInfo = await this.uploadService.uploadFile(file, uploadFileDto);
    return new UploadFileResponseDto(200, '上传成功', uploadFileInfo);
  }

  @Post('files')
  @UseInterceptors(FilesInterceptor('files'))
  async uploadFiles(@UploadedFiles() files: Express.Multer.File[], @Body() uploadFileDto?: UploadFileDto) {
    const uploadFileInfos = await this.uploadService.uploadFiles(files, uploadFileDto);
    return new UploadFileResponseDto(200, '上传成功', uploadFileInfos);
  }
}
